var mobId, mob, stats, modified, MaxRandom, setupTask, ostats, victor, luck;
var 复活次数 = 7;
var 准备地图 = 450012500;
var 副本名称 = "黑魔法师";
var 实例地图 = [450013800, 450013810, 450013820, 450013830, 450013840, 450013850, 450013860, 450013870];

function init() {}

function setup(f, a) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    for (var c = 0; c < 实例地图.length; c++) {
        var b = em.newInstance("黑魔法师_剧情");
        var e = b.setInstanceMap(实例地图[c]);
        e.resetPQ(f);
        e.resetFully();
        e.killAllMonsters(true);
        e.setSpawn(false)
    }
    b.startEventTimer(1000 * 60 * 40);
    b.setProperty("whiteKnight", "0");
    b.setProperty("blackKnight", "0");
    mobId = 8645045;
    mob = em.getMonster(mobId);
    var d = b.getMapInstance(450013810);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-306, 85));
    mobId = 8645046;
    mob = em.getMonster(mobId);
    var d = b.getMapInstance(450013810);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(358, 85));
    mobId = 8645048;
    mob = em.getMonster(mobId);
    var d = b.getMapInstance(450013830);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-11, 85));
    mobId = 8645049;
    mob = em.getMonster(mobId);
    var d = b.getMapInstance(450013850);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(100, 85));
    mobId = 8645050;
    mob = em.getMonster(mobId);
    var d = b.getMapInstance(450013870);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(128, 218));
    return b
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(450013800);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(c, b, a) {
    if (实例地图.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 450013810:
            c.schedule("Notice", 3000);
            break;
        case 450013830:
            c.schedule("Notice", 3000);
            break;
        case 450013850:
            c.schedule("Notice", 3000);
            break;
        case 450013870:
            c.schedule("Notice", 3000);
            break
    }
}

function onMonsterKilled(a, d) {
    if (d == 8645047) {
        check1(a)
    } else {
        if (d == 8645048) {
            var c = a.getMapInstance(450013830);
            a.schedule("Chuansong", 4300);
            c.getWeatherEffectNotice("黑魔法师喷射出未知气息，吞噬黑暗王座。", 265, 3000, 1)
        } else {
            if (d == 8645049) {
                var b = a.getMapInstance(450013830);
                a.schedule("Chuansong", 4300);
                b.getWeatherEffectNotice("压倒性气息令周围的一切瞬间灰飞烟灭。", 265, 3000, 1)
            } else {
                if (d == 8645050) {
                    a.schedule("Chuansong", 4300);
                    a.setProperty("whiteKnight", "0");
                    a.setProperty("blackKnight", "0")
                }
            }
        }
    }
    return 1
}

function Notice(a) {
    var e = a.getMapInstance(450013810);
    var d = a.getMapInstance(450013830);
    var c = a.getMapInstance(450013850);
    var b = a.getMapInstance(450013870);
    if (a.getMapInstance(450013810).getCharactersSize() != 0) {
        e.getWeatherEffectNotice("为了与黑魔法师对峙，必须要消灭保护他的创造和破坏骑士。", 265, 8000, 1);
        player.getAPI().addPopupSay(0, 5000, "这里发生的攻击似乎遭到了创造或破坏的诅咒。\r\n如果同时中了两种诅咒，将会受到#b巨大伤害#k，一定要小心", "", 0)
    } else {
        if (a.getMapInstance(450013830).getCharactersSize() != 0) {
            d.getWeatherEffectNotice("终于站到黑魔法师面前了。拼尽全力消灭他吧。", 265, 8000, 1);
            player.getAPI().addPopupSay(0, 4000, "这里发生的攻击似乎遭到了创造或破坏的诅咒。\r\n如果同时中了两种诅咒，将会受到#b巨大伤害#k，一定要小心", "", 0)
        } else {
            if (a.getMapInstance(450013850).getCharactersSize() != 0) {
                c.getWeatherEffectNotice("他似乎得到了神的权能。但哪怕对方是神，也要为了大家消灭他。", 265, 8000, 1);
                player.getAPI().addPopupSay(3003902, 4000, "#face1#走吧。我去复仇，你去守护世界。", "", 0)
            } else {
                if (a.getMapInstance(450013870).getCharactersSize() != 0) {
                    b.getWeatherEffectNotice("发现了近乎于神之人的权能。是创造还是破坏，必须要选择一种力量。", 265, 3000, 1)
                }
            }
        }
    }
}

function check1(a) {
    var b = a.getMapInstance(450013810);
    b.getWeatherEffectNotice("创造与破坏的骑士倒下，通向黑魔法师之路开启。", 265, 3000, 1);
    a.schedule("Chuansong", 4300);
    em.setProperty("state", "2")
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == 8880500 || d == 8880501 || d == 8880502 || d == 8880504) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function Chuansong(b, a) {
    if (b.getMapInstance(450013810).getCharactersSize() != 0) {
        warp(b, 450013820, 0)
    } else {
        if (b.getMapInstance(450013830).getCharactersSize() != 0) {
            warp(b, 450013840, 0)
        } else {
            if (b.getMapInstance(450013850).getCharactersSize() != 0) {
                warp(b, 450013860, 0)
            } else {
                if (b.getMapFactory().getMap(450013870).getCharactersSize() != 0) {
                    warp(b, 993070082, 0)
                }
            }
        }
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPlayerKilled(b, a) {}

function onPartyDisbanded(a) {
    on玩家退场(a, player, false)
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onItemPickedUp(b, a, c) {};